package com.eazyimage.lab.controller;


import com.eazyimage.lab.entity.Response;
import com.eazyimage.lab.service.DeleteDatasetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;

@RestController
public class DeleteDatasetController {
    @Autowired
    DeleteDatasetService service;

    @RequestMapping("/deletedataset")
    public Response deletedataset(@RequestParam("datasetId") int datasetId){
        boolean deddata = service.DeleteDataset(datasetId);
        if (deddata == true){
            try {
                File file = new File("/easyimage/backend-Flask/static/dataset/" + datasetId);
                //File file = new File("F://temp2");
                service.DeleteDatasetFile(file);
            }catch (Exception e){
                e.printStackTrace();
                return Response.fail();
            }
            return Response.success();
        }
        return Response.fail();
    }

}
